unit MainDM;

interface

uses
  System.SysUtils, System.Classes, Vcl.PlatformDefaultStyleActnCtrls,
  System.Actions, Vcl.ActnList, Vcl.ActnMan, Forms, Data.DbxSqlite, Data.FMTBcd,
  Data.DB, Data.SqlExpr;

type
  TdmMain = class(TDataModule)
    ActionManager: TActionManager;
    acTableViewData: TAction;
    conSQLite: TSQLConnection;
    qrTableList: TSQLQuery;
    procedure DataModuleCreate(Sender: TObject);
    procedure acTableViewDataExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  AppDir: string;
  dmMain: TdmMain;

const
  PackagesFileName = 'package.txt';

implementation

uses Main, TableView;
{ %CLASSGROUP 'Vcl.Controls.TControl' }

{$R *.dfm}

procedure TdmMain.acTableViewDataExecute(Sender: TObject);
var
  fmTableView: TfmTableView;
begin
  fmTableView := TfmTableView.Create(Self);
  try
    fmTableView.dsTable.Close;
    fmTableView.sqlTable.TableName := fmMain.lbxNames.Items[fmMain.lbxNames.ItemIndex];
    fmTableView.dsTable.Open;

    fmTableView.ShowModal;
  finally
    fmTableView.Free;
  end;
end;

procedure TdmMain.DataModuleCreate(Sender: TObject);
var
  FileName: string;
begin
  AppDir := ExtractFilePath(Application.ExeName);
  FileName := AppDir + PackagesFileName;
  if not FileExists(FileName) then
  begin
    FileCreate(FileName);
  end;
end;

end.
